package cn.edu.bjut.homework.chapter5;

import cn.edu.bjut.homework.chapter4.*;

public class ChapterFive {
    public static void main(String[] args) {
        question1();
        System.out.println();
        question2();
        System.out.println();
        question3();
    }

    public static void printDoubleArray(double[] a) {
        for (int i = 0; i < a.length; i++) {
            System.out.print(a[i] + " ");
        }
        System.out.println();
    }

    public static void printIntArray(int[] a) {
        for (int i = 0; i < a.length; i++) {
            System.out.print(a[i] + " ");
        }
        System.out.println();
    }

    public static void printAlphabet() {
        for (int i = 0; i < 26; i++) {
            System.out.print((char) ('a' + i) + " ");
        }
        System.out.println();
    }

    public static void printDigits() {
        for (int i = 0; i < 10; i++) {
            System.out.print(i + " ");
        }
        System.out.println();
    }

    public static void question1() {
        double[][] v = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
        Matrix m = new Matrix(v);
        Matrix t = m.transpose();
        System.out.println(m.toString());
        System.out.println(t.toString());

        double[] row = m.getRow(1);
        double[] col = m.getCol(1);
        System.out.println("row 1: ");
        printDoubleArray(row);
        System.out.println("col 1: ");
        printDoubleArray(col);
    }

    public static void question2() {
        String test = "A quick brown fox jumps over the lazy dog. 3.141592653589793238462643383279";
        CharCounter cc = new CharCounter(test);

        int[] letterCount = cc.getLetterCount();
        int[] digitCount = cc.getDigitCount();
        System.out.println("Letter Count: ");
        printAlphabet();
        printIntArray(letterCount);
        System.out.println("Digit Count: ");
        printDigits();
        printIntArray(digitCount);

        char ch = '3';
        int count = cc.getCharCount(ch);
        System.out.println("Count of " + ch + ": " + count);
    }

    public static void question3() {
        Patent[] apps = new Patent[5];
        apps[0] = new Patent(14725838,
                "2015-05-29",
                "A23B  5/04, A23B  5/045",
                "A23B  5/04, A23B  5/45, A23L 15/20",
                'F',
                'I'
        );
        apps[1] = new Patent(14814205,
                "2015-07-30",
                "A61H 33/00, C01B 33/107, E04B  1/84",
                "A61H 33/6063, A61H 33/6042",
                'F',
                'I'
        );
        apps[2] = new Patent(15189723,
                "2016-06-22",
                "D04B  1/00",
                "B65H2301/44514, C01B 33/1071, F16F 15/2, H01L 27/14641",
                'L',
                'A'
        );
        apps[3] = new Patent(14711011,
                "2015-05-13",
                "B32B 17/10, B32B 27/32",
                "G06F  3/485",
                'L',
                'A'
        );
        apps[4] = new Patent(14515267,
                "2014-10-15",
                "F16F 15/02, G09G  5/34, G06F  3/0485",
                "A01B 15/06, A01B 15/06",
                'L',
                'I'
        );
        for (int i = 0; i < apps.length; i++) {
            System.out.println(apps[i].toString());
        }

    }
}
